﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace Ruandao.MiniFace
{
    public static class ControllerExtensions
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="path">模板的相对路径，基于当前模板位置。</param>
        /// <returns></returns>
        public static PageResult TemplatePage(this Controller controller, string templateUrlBase, string filePath) 
        {
            Template template = new Template(templateUrlBase, filePath);
            return new PageResult(template);
        }

        public static PageResult TemplatePage(this Controller controller, string templateUrlBase, string filePath, Dictionary<string, object> variables) 
        {
            Template template = new Template(templateUrlBase, filePath);
            return new PageResult(template,variables);
        }
        /// <summary>
        /// 不提供TemplateUrlBase参数，而是由Template.GetUrlBase()自动获取，如果没有提供GetUrlBase()或者该方法返回null，那么使用默认值"~/Templates/Default/"。
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static PageResult TemplatePage(this Controller controller, string filePath) 
        {
            Template template = new Template(filePath);
            return new PageResult(template);
        }
        public static PageResult TemplatePage(this Controller controller, string filePath, Dictionary<string, object> variables) 
        {
            Template template = new Template(filePath);
            return new PageResult(template, variables);
        }
    }
}
